<template>
  <div class="header-wrapper">
    <div class="header-box flex-x-bet-y-center">
      <span>欢迎来到设备租赁平台~</span>
      <div class="flex-y-center" v-if="!userInfo.id">
        <router-link to="/login" class="login-btn">请登录</router-link>
        <router-link to="/register" class="register-btn">注册</router-link>
      </div>
      <div class="flex-y-center" style="cursor:pointer" @click="toUserIndex" v-else>
        <el-image :src="require('@/assets/img/default-avatar.png')" class="avatar" v-if="userInfo.avatar === '默认头像' || !userInfo.avatar"></el-image>
        <el-image :src="userInfo.avatar | formatFile" class="avatar" v-else></el-image>
        <span class="nickname">{{ userInfo.nickname }}</span>
        <i class="el-icon-arrow-right"></i>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
  name: "PageFirstHeader",
  data() {
    return {};
  },
  computed:{
    ...mapGetters(['userInfo', 'token'])
  },
  methods: {
    toUserIndex(){
      this.$router.push('/user');
    }
  },
};
</script>

<style lang="scss" scoped>
.header-wrapper {
  display: flex;
  align-items: center;
  width: 100%;
  height: 50px;
  background: #f4f4f4;

  .header-box {
    margin: auto;
    width: 1200px;
    font-weight: 400;
    font-size: 16px;
    color: #999999;
  }

  .login-btn {
    font-weight: 400;
    font-size: 16px;
    color: #fe5a13;
    margin-right: 40px;
    cursor: pointer;
    text-decoration: none;
  }

  .register-btn {
    cursor: pointer;
    text-decoration: none;
  }
}

.avatar{
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 12px;
}

.nickname{
  font-weight: normal;
font-size: 14px;
color: #333333;
}
</style>
